package com.sws.web.controller.ry_rongyue.push;

import java.util.List;

import com.sws.common.core.domain.entity.SysRole;
import com.sws.common.core.domain.model.LoginUser;
import com.sws.common.utils.SecurityUtils;
import jakarta.servlet.http.HttpServletResponse;


import com.sws.push.domain.RyMessagePush;
import com.sws.push.service.IRyMessagePushService;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sws.common.annotation.Log;
import com.sws.common.core.controller.BaseController;
import com.sws.common.core.domain.AjaxResult;
import com.sws.common.enums.BusinessType;
import com.sws.common.utils.poi.ExcelUtil;
import com.sws.common.core.page.TableDataInfo;

/**
 * 消息推送Controller
 * 
 * @author cx
 * @date 2025-06-20
 */
@RestController
@RequestMapping("/ry/push/push")
public class RyMessagePushController extends BaseController
{
    @Autowired
    private IRyMessagePushService ryMessagePushService;

    /**
     * 查询消息推送列表
     */
    @PreAuthorize("@ss.hasPermi('ry/push:push:list')")
    @GetMapping("/list")
    public TableDataInfo list(RyMessagePush ryMessagePush) {

        startPage();
        List<RyMessagePush> list = ryMessagePushService.selectRyMessagePushList(ryMessagePush);
        return getDataTable(list);
    }

    /**
     * 导出消息推送列表
     */
    @PreAuthorize("@ss.hasPermi('ry/push:push:export')")
    @Log(title = "消息推送", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RyMessagePush ryMessagePush)
    {
        List<RyMessagePush> list = ryMessagePushService.selectRyMessagePushList(ryMessagePush);
        ExcelUtil<RyMessagePush> util = new ExcelUtil<RyMessagePush>(RyMessagePush.class);
        util.exportExcel(response, list, "消息推送数据");
    }

    /**
     * 获取消息推送详细信息
     */
    @PreAuthorize("@ss.hasPermi('ry/push:push:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ryMessagePushService.selectRyMessagePushById(id));
    }

    /**
     * 新增消息推送
     */
    @PreAuthorize("@ss.hasPermi('ry/push:push:add')")
    @Log(title = "消息推送", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RyMessagePush ryMessagePush)
    {
        return toAjax(ryMessagePushService.insertRyMessagePush(ryMessagePush));
    }

    /**
     * 修改消息推送
     */
    @PreAuthorize("@ss.hasPermi('ry/push:push:edit')")
    @Log(title = "消息推送", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RyMessagePush ryMessagePush)
    {
        return toAjax(ryMessagePushService.updateRyMessagePush(ryMessagePush));
    }

    /**
     * 删除消息推送
     */
    @PreAuthorize("@ss.hasPermi('ry/push:push:remove')")
    @Log(title = "消息推送", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ryMessagePushService.deleteRyMessagePushByIds(ids));
    }

    /**
     * 确认消息
     */
    @PreAuthorize("@ss.hasPermi('ry/push:push:confirm')")
    @Log(title = "消息确认", businessType = BusinessType.UPDATE)
    @PutMapping("/confirm/{id}")
    public AjaxResult confirm(@PathVariable Long id) {
        return toAjax(ryMessagePushService.confirmRyMessagePush(id));
    }

    /**
     * 批量确认消息
     */
    @PreAuthorize("@ss.hasPermi('ry/push:push:confirm')")
    @Log(title = "消息批量确认", businessType = BusinessType.UPDATE)
    @PutMapping("/confirmBatch")
    public AjaxResult confirmBatch(@RequestBody Long[] ids) {
        return toAjax(ryMessagePushService.confirmRyMessagePushBatch(ids));
    }

    @GetMapping("/contactList")
    public AjaxResult contactList(String keyword) {
        return success(ryMessagePushService.selectContactList(keyword));
    }
}
